package com.yy.controller.admin;

import com.yy.controller.service.EmployeeService;
import com.yy.dto.EmployeePageQueryDTO;
import com.yy.entity.Employee;
import com.yy.result.PageResult;
import com.yy.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/employee")
@Slf4j
@Api(tags = "员工相关接口")
public class EmployeeController {
    @Autowired
   private EmployeeService employeeService;


    /**
     * 分页查询员工列表
     * @param employeePageQueryDto
     * @return
     */
    @GetMapping("/list")
    @CrossOrigin
    @ApiOperation(value = "分页查询员工列表")
    public Result<PageResult> getPageList(EmployeePageQueryDTO employeePageQueryDto){
       log.info("employeePageQueryDto:{}",employeePageQueryDto);
       //调用service查询
       PageResult pageResult=employeeService.getPageList(employeePageQueryDto);
      return  Result.success(pageResult);
    }

    /**
     * 删除员工
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @CrossOrigin
    @ApiOperation(value = "删除员工")
    public Result<String> deleteEmployee(@PathVariable("id") Long id){
        log.info("id:{}",id);
        employeeService.deleteEmployee(id);
        return  Result.success();
    }

    /**
     * 新增员工
     * @param employee
     * @return
     */
    @PostMapping("/add")
    @CrossOrigin
    @ApiOperation("新增员工")
    public  Result<String> addEmployee(@RequestBody Employee employee){
        log.info("employee:{}",employee);
        employeeService.addEmployee(employee);
        return  Result.success();
    }

    /**
     * 更新员工
     * @param employee
     * @return
     */
    @PutMapping("/update")
    @CrossOrigin
    @ApiOperation("更新员工信息")
    public  Result<String> updateEmployee(@RequestBody Employee employee){
        log.info("employee:{}",employee);
        employeeService.updateEmployee(employee);
       return Result.success();
    }
}
